LaTeX notes
LaTeX WIKI Books
LaTeX/Macros
There are situations where LaTeX does not provide a command or environment that matches your needs, or the output of produced by some existing command may not meet your requirements. When this happens, we can teach LaTeX new tricks:
New Commands
To add your own command, use
name is the new command name, note that name can not contain digits. num specifies the number of arguments the new command takes (up to 9). If missing it defaults to 0, i.e. no argument allowed. definition is the text to be replaced.
A simple tex replacement:
Commands take arguments:
Note that there is no overriding function in LaTeX, so you have to give them different names even when two commands only differ in the number of arguments.
Use \renewcommand to explicityl overwrite an existing command. Use \providecommand to let LaTeX silently ignore the new command if the command is already defined.
If you want a default parameter for \newcommand, use the form
This will make first argument optional, and if not specified, use the value default.
For example:
Some commands are fragile, that is they fail in some environments. If a macro works in body text but not (for example) in a figure caption, then replace the \newcommand{\MyCommand} with \DeclareRobustCommand{\MyCommand} in the preamble. This is especially true for macros which, when expanded, produce text that is written to a .aux file.
Package General Info
How to find documentation for a specific package
texdoc <package-name>
Specific Package Notes
algorithms Bundle   algorithm and algorithmic
Note that algorithms is a bundle which provide algorithm and algorithmic package, you should use \usepackage{algorithm} or \usepackage{algorithmic} instead of \usepackage{algorithms}.
This package provides two environments, algorithmic and algorithm, which are designed to be used together but may be used saparately depending on the necessities of the user. The algorithmic environment provides an environment for describing algorithms and the algorithm environment provids a "float" wrapper for algorithms (implemented using algorithmic or some other methdo at the user's option).
The algorithmic package
This package provides a number of commands for typesettings popular algorithmic constructus.
- Simple Statement
- if-then-else- In the third forms there is no limit placed on the number of - \ELSIFthat may be used.
- forloop- You can use - \TOconnective for distinct to text.
- whileloop
- repeat-untilloop
- Infinit loop
- Logic connectivesWe have \AND,\OR,\XOR,\NOT.
- Precondition
- Postcondition
- Returning ValuesTrue and false values: \TRUEand\FALSE.
- Printing messages
- CommentsFor comments on the same line with \IFetc. constructs, use the optional argument.